import router from '/@/router'
import supports = CSS.supports;
import {debug} from "util";

export class ClickEntNumHandel {
    private type = "";
    private other = "";
    private data = "";
    private queryJson = {
        flagArea: "",
        dataTime: "",
        orderColumn: "",
        orderFormat: "",
        centralEnterprise: ""
    };

    constructor(obj: any) {
        this.queryJson.flagArea = obj.flagArea;
        this.queryJson.dataTime = obj.dataTime;
        this.queryJson.orderColumn = obj.orderColumn;
        this.queryJson.orderFormat = obj.orderFormat;
        this.queryJson.centralEnterprise = obj.centralEnterprise;
        this.data = obj.data;
        this.type = obj.type;
        this.other = obj.other;
        this.init();
    }

    private init() {
        if (this.data == "0") {
            return;
        }
        this.render();
        this.setOrder();
        this.go();
    }

    private setOrder() {
        if (this.queryJson.orderColumn == null || this.queryJson.orderColumn == undefined || this.queryJson.orderColumn == "") {
            this.queryJson.orderColumn = "taxAcc";
        }
        if (this.queryJson.orderFormat == null || this.queryJson.orderFormat == undefined || this.queryJson.orderFormat == "") {
            this.queryJson.orderFormat = "desc";
        }
    }

    private render() {
        let entTypeClass = new Enterprise();
        switch (this.type) {
            case 'NewEnt':
                entTypeClass = new NewEnterpriseNum();
                break;
            case 'flagEntNum':
                entTypeClass = new EnterpriseNum();
                break;
            case 'keyEnterprise':
                entTypeClass = new keyEnterpriseNum(this.other);
                break;
            case 'enterpriseType':
                entTypeClass = new EnterpriseType(this.other);
                break;
            case 'overallSituation':
                entTypeClass = new GeneralSituationOfTheEnterprise(this.other);
                break;
            case 'changeOfEnterprise':
                entTypeClass = new ChangeOfEnterpriseMain(this.other);
                break;
            case 'regCapital':
                entTypeClass = new RegCapital(this.other);
                break;
            case 'entScale':
                entTypeClass = new EntScale(this.other);
                break;
            case 'areaEco':
                entTypeClass = new AreaEco(this.other);
                break;
            case 'regionEco':
                entTypeClass = new RegionEco(this.other);
                break;
            case 'buildingEconomy':
                entTypeClass = new BuildingEconomy(this.other);
                break;
            case 'buildingIndustry':
                entTypeClass = new BuildingIndustry(this.other);
                break;
            case 'CentralEnterprise':
                entTypeClass = new CentralEnterprise(this.other);
            default:
                break;
        }
        let queryClass = entTypeClass.getQueryJson();
        Object.assign(this.queryJson, queryClass);
    }

    private go() {
        router.push({
            name: "entList",
            query: this.queryJson,
        });
    }
}

class Enterprise {

    constructor() {
    }

    getQueryJson() {
    };

}

//企业数
class EnterpriseNum extends Enterprise {
    getQueryJson() {
        return {
            flagEntNum: '1'
        }
    };
}

//新注册企业
class NewEnterpriseNum extends Enterprise {

    getQueryJson() {
        return {isNewReg: '1'}
    }
}

//楼宇行业分析
class BuildingIndustry extends Enterprise {
    private other;

    constructor(other: any) {
        super();
        this.other = other;
    }

    getQueryJson() {
        let obj = {
            buildingIndustry: '1'
        }
        this.other["flagTaxEntNum"] == "1" ? obj.flagTaxEntNum = '1' : obj.flagEntNum = '1';
        if (this.other["estateId"]) {
            obj["estateId"] = this.other["estateId"];
        }
        if (this.other["industryMtypeId"]) {
            obj["industryMtypeId"] = this.other["industryMtypeId"];
        }
        return obj;
    }
}

//重点企业
class keyEnterpriseNum extends Enterprise {
    private other;

    constructor(other: any) {
        super();
        this.other = other;
    }

    getQueryJson() {
        let obj = {
            flagEntNum: '',
            flagTaxEntNum: '',
            keyEntPrise: '1',
            labelName: this.other["labelName"],
        }
        this.other["flagTaxEntNum"] == "1" ? obj.flagTaxEntNum = '1' : obj.flagEntNum = '';
        if (this.other["estateId"]) {
            obj["estateId"] = this.other["estateId"];
        }
        return obj;
    }
}

//央企大院企业
class CentralEnterprise extends Enterprise {
    private other;

    constructor(other: any) {
        super();
        this.other = other;
    }

    getQueryJson() {
        let obj = {
            estateId: this.other["estateId"],
            flagMatchGroup: this.other["flagMatchGroup"],
        }
        this.other["flagTaxEntNum"] == "1" ? obj["flagTaxEntNum"] = '1' : obj["flagEntNum"] = '1';


        //非央企
        if (this.other["notCentralEnterprise"] == '1') {
            obj["labelName"] = '中央企业';
            obj["notCentralEnterprise"] = '1';
        }

        //央企
        if (this.other["centralEntNum"] = '1') {
            obj["flagEntNum"] = '1';
        }

        return obj;
    }
}

//企业类型
class EnterpriseType extends Enterprise {
    private other;

    constructor(other: any) {
        super();
        this.other = other;
    }

    getQueryJson() {
        let queryJson = {};
        queryJson[this.other["types"]] = "1";
        if (this.other["flagTaxEntNum"] == "1") {
            queryJson["flagTaxEntNum"] = "1";
            if (this.other["types"] == "isNewReg") {
                queryJson["flagTaxEntNumNewreg"] = "1"
            } else {
                queryJson["flagTaxEntNumCancel"] = "1"
            }
        }
        let typeOfEnt = ["entBtypeId", "entStypeId"];
        queryJson[typeOfEnt[this.other["entTypeLevel"] - 1]] = this.other["entTypeId"];
        return queryJson;
    }
}

//企业总体情况
class GeneralSituationOfTheEnterprise extends Enterprise {
    private other;

    constructor(other: any) {
        super();
        this.other = other;
    }

    getQueryJson() {
        let queryJson = {};
        let obj = {
            dataFlagSamr: this.other["row"].flagSamrMark,
            dataFlagTax: this.other["row"].flagTaxMark,
            flagNbsAboveScale: this.other["row"].flagNbsAboveScaleMark,
        };
        this.other["flagTaxEntNum"] == "1" ? queryJson["flagTaxEntNum"] = '1' : queryJson["flagEntNum"] = '1';
        Object.keys(obj).forEach((key) => {
            if (obj[key] == "1" || obj[key] == "0") {
                queryJson[key] = obj[key];
            }
        });
        return queryJson;
    }
}

//企业主体变化
class ChangeOfEnterpriseMain extends Enterprise {
    private other;

    constructor(other: any) {
        super();
        this.other = other;
    }

    getQueryJson() {
        let queryJson = {};
        queryJson[this.other["types"]] = "1";
        if (this.other["types"] == "isMonthNewReg") {
            queryJson["orderColumn"] = "regCapital";
            queryJson["orderFormat"] = "desc";
        }
        return queryJson;
    }
}

//注资规模
class RegCapital extends Enterprise {
    private other;

    constructor(other: any) {
        super();
        this.other = other;
    }

    getQueryJson() {
        let queryJson = {
            regCapital: this.other["regCapital"],
        };
        queryJson[this.other["entType"]] = "1";
        return queryJson;
    }
}

//企业规模
class EntScale extends Enterprise {
    private other;

    constructor(other: any) {
        super();
        this.other = other;
    }

    getQueryJson() {
        let queryJson = {
            entScaleId: this.other["entScaleId"],
        };
        queryJson[this.other["entType"]] = "1";
        return queryJson;
    }
}

//区域分析
class AreaEco extends Enterprise {
    private other;

    constructor(other: any) {
        super();
        this.other = other;
    }

    getQueryJson() {
        let queryJson = {};
        queryJson[this.other["entType"]] = "1";
        return queryJson;
    }
}

//街镇分析
class RegionEco extends Enterprise {
    private other;

    constructor(other: any) {
        super();
        this.other = other;
    }

    getQueryJson() {
        let queryJson = {
            regionId: this.other["regionId"]
        };
        queryJson[this.other["entType"]] = "1";
        return queryJson;
    }
}

//楼宇经济
class BuildingEconomy extends Enterprise {
    private other;

    constructor(other: any) {
        super();
        this.other = other;
    }

    getQueryJson() {
        let queryJson = {
            estateId: this.other["estateId"]
        };
        this.other["flagTaxEntNum"] == "1" ? queryJson["flagTaxEntNum"] = '1' : queryJson["flagEntNum"] = '1';
        return queryJson;
    }
}